package com.cheng.web.action.base;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;

import com.cheng.bos.actionUtils.ActionUtils;
import com.cheng.domain.base.TakeTime;
import com.cheng.service.base.TaketimeService;
import com.opensymphony.xwork2.ActionContext;

@Namespace("/taketime")
@ParentPackage("json-default")
@Controller
@Scope("prototype")
public class TaketimeAction extends ActionUtils<TakeTime> {

	@Autowired
	private TaketimeService taketimeService;
	
	//获取所有的取派时间
	@Action(value="gettaketime",results={@Result(name="success",type="json")})
	public String getAllTaketime(){
		List<TakeTime> list = taketimeService.getAllTaketime();
		ActionContext.getContext().getValueStack().push(list);
		return SUCCESS;
	}
	//分页获取取派时间
	@Action(value="taketime_pagequery",results={@Result(name="success",type="json")})
	public String getTaketimePage(){
		Pageable pageable = new PageRequest(page-1,rows);
		Page<TakeTime> pageData = taketimeService.getTaketimePage(pageable);
		pushPageDataToValueStack(pageData);
		return SUCCESS;
	}

	//保存取派时间
	@Action(value="taketime_save",results={@Result(name="success",type="redirect",location="../pages/base/take_time.html")})
	public String saveTaketime(){
		taketimeService.saveTaketime(model);
		return SUCCESS;
	}
	
	
	//属性驱动获取id
	private String ids;

	public void setIds(String ids) {
		this.ids = ids;
	}
	//删除取派时间
	@Action(value="deltaketime",results={@Result(name="success",type="redirect",location="../pages/base/take_time.html")})
	public String deleteTaketime(){
		if ("".equals(ids)) {
			return SUCCESS;
		}
		String[] strs = ids.split(",");
		for (String string : strs) {
			Integer id = Integer.parseInt(string);
			taketimeService.delteTaketime(id);
		}
		return SUCCESS;
	}
	//作废取派时间
	@Action(value="canceltaketime",results={@Result(name="success",type="redirect",location="../pages/base/take_time.html")})
	public String cancelTaketime(){
		if ("".equals(ids)) {
			return SUCCESS;
		}
		String[] strs = ids.split(",");
		for (String string : strs) {
			Integer id = Integer.parseInt(string);
			taketimeService.cancelTaketime(id);
		}
		return SUCCESS;
	}
	//还原取派时间
	@Action(value="restoretaketime",results={@Result(name="success",type="redirect",location="../pages/base/take_time.html")})
	public String restoreTaketime(){
		if ("".equals(ids)) {
			return SUCCESS;
		}
		String[] strs = ids.split(",");
		for (String string : strs) {
			Integer id = Integer.parseInt(string);
			taketimeService.restoreTaketime(id);
		}
		return SUCCESS;
	}
}
